package com.lfs.market.config;

import com.lfs.market.job.MyJob;
import lombok.extern.slf4j.Slf4j;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author lfs
 * @date 2025/6/30 11:18:20
 * todo 注意采用动态创建定时任务时，要注释掉@Configuration，这个配置类是不需要的
 * 采用动态调度的方式则不需要这个Config
 * 动态调度： controller(jobUtil.createJob) + 具体任务(MyJob)
 * jobUtil.createJob(创建任务) 与 QuartzConfig 中代码一致，QuartzConfig本质就为创建一个任务
 */
//@Configuration
@Slf4j
public class QuartzConfig {
    @Bean
    public JobDetail jobDetail() {
        return JobBuilder.newJob(MyJob.class)
                .storeDurably()
                .withIdentity("demoJob", "demoGroup")
                .usingJobData("count", 1)
                .build();
    }

    @Bean
    public Trigger trigger() {
        String croExpression = "0/5 * * * * ? *";
        return TriggerBuilder.newTrigger()
                .withIdentity("demoTrigger", "demoGroup")
                .forJob(jobDetail())
                .withSchedule(CronScheduleBuilder.cronSchedule(croExpression))
                .build();
    }
}
